package com.webreport.utils;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.Security;

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;

import org.apache.commons.io.FileUtils;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.crypto.password.StandardPasswordEncoder;

public class EncryptUtil {
    //从配置文件中获得
	private static final String keyfile="deslldkie";
    private static final String SITE_WIDE_SECRET = "2424dssfe54117891weiop1805vgfrr711L";
    private static Key key;
    private static final PasswordEncoder encoder = new StandardPasswordEncoder(
       SITE_WIDE_SECRET);
 
    public static String encrypt(String rawPassword) {
         return encoder.encode(rawPassword);
    }
 
    public static boolean match(String rawPassword, String password) {
         return encoder.matches(rawPassword, password);
    }
    
    public static void main(String[] args) {
		System.out.println(EncryptUtil.encrypt("每次结果都不一样伐?"));
		System.out.println(EncryptUtil.encrypt("每次结果都不一样伐?"));
        System.out.println(EncryptUtil.encrypt("每次结果都不一样伐?"));
		System.out.println(EncryptUtil.encrypt("每次结果都不一样伐?"));
        System.out.println(EncryptUtil.encrypt("每次结果都不一样伐?")); 
        String a = EncryptUtil.encrypt("每次结果都不一样伐?");
        System.out.println(EncryptUtil.match("每次结果都不一样伐?",a)); 
        //但是把每次结果拿出来进行match，你会发现可以得到true。
	}
 }

